
if (SERVER) then

	AddCSLuaFile('shared.lua')

end

if (CLIENT) then

	SWEP.PrintName			= "Hopwire"			
	SWEP.Author				= "Foss"
	SWEP.Contact			= "Don't."
	SWEP.Purpose			= "Throw a hopwire grenade."
	SWEP.Instructions		= "Lob a grenade at the enemy."

	SWEP.Slot				= 4
	SWEP.SlotPos			= 3
	SWEP.ViewModelFOV		= 70

end

SWEP.ViewModel      		= "models/weapons/v_hopwire.mdl"
SWEP.WorldModel   			= "models/weapons/w_hopwire.mdl"

SWEP.Spawnable				= true
SWEP.AdminSpawnable			= true

SWEP.Primary.ClipSize		= 1
SWEP.Primary.DefaultClip	= 3
SWEP.Primary.Automatic   	= false
SWEP.Primary.Ammo         	= "grenade"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic   	= false
SWEP.Secondary.Ammo         = "none"

SWEP.Delay					= CurTime() + 1.2
SWEP.Timer					= 2
SWEP.ReDraw					= false
 
function SWEP:Initialize()

	if (SERVER) then
		self:SetWeaponHoldType("grenade")
	end
	
end

function SWEP:Deploy()

	self.ReDraw = true
	
	return true
	
end

function SWEP:Holster()

	self.ReDraw = false
	
	return true
	
end

function SWEP:Think()

	if (self.Weapon:Clip1() <= 0 and self.ReDraw and (self.Delay <= CurTime())) then
		self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
		self:Reload()
	end

end

function SWEP:ThrowGrenade(ply)

	local ent = ents.Create("hopwire_grenade")
	ent:SetPos(ply:GetShootPos())
	ent:SetAngles(ply:EyeAngles())
	ent:SetOwner(ply)
	ent:SetNWFloat("timer", self.Timer)
	ent:SetVelocity( Vector( 50000, 50000, 50000 ) )
	ent:Spawn()
	ent:Activate()
	//ent:GetPhysicsObject():AddAngleVelocity(Angle(600, AngleRand().y * 1200, 0))

	self.ReDraw = true

end

function SWEP:PrimaryAttack()

	if !self.ReDraw then
		return
	end
	
	self:ThrowGrenade(self.Owner)
	self.Weapon:SendWeaponAnim(ACT_VM_THROW)
	self.Weapon:SetNextPrimaryFire(self.Delay)
	self.Delay = CurTime() + 1.2
	self:TakePrimaryAmmo(1)
	
end
	
function SWEP:Reload()

	return true

end

